/*
 * 版权所有 (c) 2022-2099 TBIT。保留所有权利。
 */

package com.tbit.main.controller.interceptor;

import com.alibaba.ttl.TransmittableThreadLocal;
import com.tbit.main.pojo.AccountUser;
import lombok.Data;

/**
 * 登录用户上下文
 *
 * @author yao
 * @since 2024/7/8 14:36
 */
@Data
public class LoginUserContextHolder {

    private static final ThreadLocal<AccountUser> LOGIN_USER_CONTEXT = new TransmittableThreadLocal<>();

    public static void setLoginUser(AccountUser accountUser) {
        LOGIN_USER_CONTEXT.set(accountUser);
    }

    public static AccountUser getLoginUser() {
        return LOGIN_USER_CONTEXT.get();
    }

    public static Integer getLoginUserId() {
        return LOGIN_USER_CONTEXT.get().getAccountUserId();
    }

    public static void removeLoginUser() {
        LOGIN_USER_CONTEXT.remove();
    }

}
